package com.zd.hamster.sys.web;

/**
 * API返回对象
 * @author ZhangDi
 *
 */
public class Result {

	private final static String MSG_SUCCESS =  "操作成功";
	private final static String MSG_ERROR =  "操作失败";
	
	private int code;
	private String msg;
	private Object data;
	
	public Result(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	
	public Result(int code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	public static Result success() {
		return new Result(200, MSG_SUCCESS);
	}
	
	public static Result success(Object data) {
		return new Result(200, MSG_SUCCESS, data);
	}
	
	public static Result error() {
		return Result.error(MSG_ERROR);
	}
	
	public static Result error(String msg) {
		return Result.error(500, msg);
	}
	
	public static Result error(int code, String msg) {
		return new Result(code, msg);
	}

	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public Object getData() {
		return data;
	}
}
